let events=require('events');
let emitter=new events.EventEmitter();
emitter.setMaxListeners(8);

function f1(){
    console.log('first callback');
    emitter.removeListener('connection',f2);
}
function f2(){
    console.log('second callback');
    emitter.off('connection',f3);
}
function f3(){
    console.log('third callback');
}

emitter.on('connection',f1);
emitter.prependListener('connection',f2);
emitter.addListener('connection',f3);
emitter.once('connection',function(){
    console.log('only event one')
});
emitter.prependOnceListener('connection',function(){
    console.log('only event two');
});

for(let i=0;i<3;i++){
    console.log(emitter.listenerCount('connection'));
    emitter.emit('connection');
    console.log('');
}

emitter.removeAllListeners('connection');
emitter.emit('connection');
